package com.example.springboot.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * @auther: Wyz
 * @date: 2023/5/9 10:45
 * @return
 */
public class Record {


    public static void main(String[] args) {
//        write("2,","123");
        read("123");
    }

    public static void write(String data,String documentName){
        String fileName = "D://zhuomian\\错误pdf记录\\"+documentName+".txt";
        try {
            File file = new File(fileName);
            FileWriter fw = new FileWriter(file, true); // append参数设置为true，表示追加到文件结尾
            fw.write(data);
            fw.close();
            System.out.println("成功将数据追加到文件 " + fileName + " 的末尾");
        } catch (IOException e) {
            System.err.println("写入文件失败：" + e.getMessage());
        }
    }

    public static String read(String documentName) {
        String fileName = "D://zhuomian\\错误pdf记录\\"+documentName+".txt";
        File file = new File(fileName);
        String s = "";
        try {
            Scanner scanner = new Scanner(file);

            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                s+=line;
            }
            System.err.println(s);
            scanner.close();
        } catch (FileNotFoundException e) {
            System.err.println("读取出错");
        }finally {
            return s;
        }
    }

}
